﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KongZhiTaiTest.ADO.NET
{
    public class AdoDBHelper
    {
		private MySqlCommand command { get; set; }
		private MySqlConnection conn { get; set; }


		/// <summary>
		/// 通过Command和DataReader读取数据
		/// </summary>
        public void CreatDBConnectByCommandAndDataReader()
        {
			//数据库连接字符串  
			String connstr = "server=rm-2ze6z4mp88p324330so.mysql.rds.aliyuncs.com;Database =ht_intl;uid=sa;pwd=@zc901205;charset=utf8";
			//建立数据库连接  
			conn = new MySqlConnection(connstr);
			MySqlDataReader reader = default;
			try
			{
				conn.Open();
				command = new MySqlCommand("select * from code_3402", conn);
				reader = command.ExecuteReader();

			}
			catch (Exception ex)
			{

				Console.WriteLine($"{ex.Message}");
			}
			DataTable dt = new DataTable();
			dt.Load(reader);
			if (dt.Rows.Count > 0)
			{
				Console.WriteLine(dt.Rows[0][0].ToString());
			}
        }
    }
}
